package com.zboot.zbootadmin.project.system.menu.entity;

import com.zboot.zbootadmin.project.system.menu.entity.vo.RouterVo;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * @Description: 前端树形下拉选菜单
 *
 * @author: zyt
 * @date: 22:22 2020/9/7
 * @param:
 * @return:
 *
 */
public class Tree implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long id;
	private String label;
	private Long parentId;
	private List<Tree> children;

	public Tree() {
	}

	public Tree(SysMenu menu)
	{
		this.id = menu.getMenuId();
		this.label = menu.getMenuName();
		this.parentId = menu.getParentId();
		this.children = menu.getChildren().stream().map(Tree::new).collect(Collectors.toList());
	}

	public Tree(RouterVo routerVo) {
		this.id = routerVo.getMenuId();
		this.label = routerVo.getMeta().getTitle();
		this.parentId = routerVo.getParentId();
		if (routerVo.getChildren()!=null) {
			this.children = routerVo.getChildren().stream().map(Tree::new).collect(Collectors.toList());
		}

	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public List<Tree> getChildren() {
		return children;
	}

	public void setChildren(List<Tree> children) {
		this.children = children;
	}
}
